package jsp.servcie;

import jsp.dao.UserDao;
import jsp.model.User;

import java.util.List;

public class UserService {
    private static UserDao userDao = new UserDao();
    public User login(String username, String password) {
        try {
            return userDao.selectByUsernamePassword(username,password);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void deleteById(int id) {
        try {
            userDao.deleteById(id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void add(User user) {
        try {
            userDao.insert(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void update(User user) {
        try {
            userDao.update(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public User getById(int id) {
        try {
            return userDao.selectById(id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public List<User> list(User user) {
        try {
            return userDao.selectList(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public List<User> list() {
        try {
            return userDao.selectList();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public User getByUsername(String username) {
        try {
            return userDao.selectByUsername(username);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
